<?php
class LocaisController extends AppController {
    public $name = 'Locais';
    public $uses = 'Local';
	
    function index() {
        $this->set('locais', $this->Local->find('all'));
    }

    public function detalhe($id = null) {
        $this->Local->id = $id;
		$location = $this->Local->read();
        $this->set('local', $location);
    }
	
	public function inserir() {
        if ($this->request->is('post')) {
            if ($this->Local->save($this->request->data)) {
                $this->Session->setFlash('Your location has been saved.');
                $this->redirect(array('action' => 'index'));
            }
        }
        $this->render('editar');
    }
	
	function editar($id = null) {
		$this->Local->id = $id;
		if ($this->request->is('get')) {
			$this->request->data = $this->Local->read();
		} else {
			if ($this->Local->save($this->request->data)) {
				$this->Session->setFlash('Your location has been updated.');
				$this->redirect(array('action' => 'index'));
			}
		}
	}
	
	function deletar($id){
		if ($this->request->is('get'))
			throw new MethodNotAllowedException();
				
		if ($this->Location->delete($id)) {
			$this->Session->setFlash("The location with id: $id has been deleted.");
			$this->redirect(array('action' => 'index'));
		}
	}
}
?>